package com.ruoyi.zyc;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.EncryptField;
import com.ruoyi.common.annotation.EncryptMethod;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping({"/test"})
public class TestEncryptController {

    public static void main(String[] args) {
        UserVo userVo1 = new UserVo(1L, "152664", "地址1", 20);
        UserVo userVo2 = new UserVo(2L, "110", "地址2", 20);
        UserVo userVo3 = new UserVo(3L, "120", "地址1", 20);
        List list = new ArrayList<UserVo>();
        list.add(userVo1);
        list.add(userVo2);
        list.add(userVo3);
        list.stream().forEach(userVo -> {
            System.out.println("加密前的数据：" + JSON.toJSONString(userVo));
        });
    }

    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo(String name) {
        try {
            return AjaxResult.success(name);
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    @EncryptMethod
    @PostMapping(value = "test")
    @ResponseBody
    public AjaxResult testEncrypt(@RequestBody UserVo user, @EncryptField String name) {
        UserVo userVo1 = new UserVo(1L, "152664", "地址1", 20);
        UserVo userVo2 = new UserVo(2L, "110", "地址2", 20);
        UserVo userVo3 = new UserVo(3L, "120", "地址1", 20);
        List list = new ArrayList<UserVo>();
        list.add(userVo1);
        list.add(userVo2);
        list.add(userVo3);
        return AjaxResult.success(list);
    }

    private UserVo insertUser(UserVo user, String name) {
        System.out.println("加密后的数据：user" + JSON.toJSONString(user));
        return user;
    }
}
